using System;
using Tutorial;
using XLua.LuaDLL;

namespace XLua.CSObjectWrap
{
	public class TutorialICalcWrap
	{
		public static void __Register(IntPtr L)
		{
			ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
			Type typeFromHandle = typeof(ICalc);
			Utils.BeginObjectRegister(typeFromHandle, L, translator, 0, 1, 0, 0);
			Utils.RegisterFunc(L, -3, "add", _m_add);
			Utils.EndObjectRegister(typeFromHandle, L, translator, null, null, null, null, null);
			Utils.BeginClassRegister(typeFromHandle, L, __CreateInstance, 1, 0, 0);
			Utils.EndClassRegister(typeFromHandle, L, translator);
		}

		[MonoPInvokeCallback(typeof(lua_CSFunction))]
		private static int __CreateInstance(IntPtr L)
		{
			return Lua.luaL_error(L, "Tutorial.ICalc does not have a constructor!");
		}

		[MonoPInvokeCallback(typeof(lua_CSFunction))]
		private static int _m_add(IntPtr L)
		{
			try
			{
				ICalc obj = (ICalc)ObjectTranslatorPool.Instance.Find(L).FastGetCSObj(L, 1);
				int a = Lua.xlua_tointeger(L, 2);
				int b = Lua.xlua_tointeger(L, 3);
				int value = obj.add(a, b);
				Lua.xlua_pushinteger(L, value);
				return 1;
			}
			catch (Exception arg)
			{
				return Lua.luaL_error(L, "c# exception:" + arg);
			}
		}
	}
}
